#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>

typedef struct SListNode
{
    int data;
    struct SListNode* next;
}SListNode;

SListNode* BuyNewNode(int x)
{
    SListNode* newnode = (SListNode*)malloc(sizeof(SListNode));
    newnode->data = x;
    newnode->next = NULL;
    return newnode;
}

void SListPop(SListNode* prev, SListNode* cur)
{
    prev->next = cur->next;
    free(cur);
    cur = NULL;
}

int main()
{
    int n = 0;
    int m = 0;
    scanf("%d %d", &n, &m);
    SListNode* phead = BuyNewNode(1);
    SListNode* cur = phead;
    for (int i = 2; i <= n; i++)
    {
        SListNode* next = BuyNewNode(i);
        cur->next = next;
        cur = next;
    }
    cur->next = phead;
    cur = phead;
    SListNode* prev = NULL;
    while (cur->next != cur)
    {
        int num = m;
        while (--num)
        {
            prev = cur;
            cur = cur->next;
        }
        SListPop(prev, cur);
        cur = prev->next;
    }
    printf("%d", cur->data);
    return 0;
}